home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / widgets-mesa / demos / tea.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-31  |  18.4 KB  |  585 lines

  1. /* tea.c -- demo program for the MesaWS widget
  2.    Copyright (C) 1995 Thorsten.Ohl @ Physik.TH-Darmstadt.de
  3.  
  4.    Parts Copyright (c) Mark J. Kilgard, 1994.  See below.
  5.  
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2 of the License, or
  9.    (at your option) any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.    $Id: tea.c,v 1.6 1996/09/27 10:21:53 ohl Exp $
  21.  
  22.  */
  23.  
  24. /* No 3D graphics package is complete without a teapot demo.
  25.    Use the cursor keys (and other MesaWorkstationWidget translations)
  26.    to move the teapot around.
  27.  
  28.    FIXME: toggling the radiobuttons sends two expose events, which is
  29.           a nuisance on affortable hardware ...
  30.  */
  31.  
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <stdarg.h>
  35. #include <math.h>
  36. #ifndef M_PI
  37. #define M_PI 3.14159265358979323846
  38. #endif
  39. #include <X11/X.h>
  40. #include <X11/Intrinsic.h>
  41. #include <X11/StringDefs.h>
  42. #include <X11/Shell.h>
  43. #include <X11/Xaw/Command.h>
  44. #include <X11/Xaw/Form.h>
  45. #include <X11/Xaw/Toggle.h>
  46. #include <GL/xmesa.h>
  47. #include <GL/gl.h>
  48. #include <GL/glu.h>
  49. #include <GL/glx.h>
  50. #include <GL/MesaWorkstation.h>
  51.  
  52. static char *RCS_Id =
  53. "@(#) $Id: tea.c,v 1.6 1996/09/27 10:21:53 ohl Exp $";
  54.  
  55. void glutSolidTeapot (GLdouble scale);
  56. void glutWireTeapot (GLdouble scale);
  57.  
  58. static GLint
  59. alloc_color (Widget w, Colormap cmap, int red, int green, int blue)
  60.   XColor xcolor;
  61.   xcolor.red = red;
  62.   xcolor.green = green;
  63.   xcolor.blue = blue;
  64.   xcolor.flags = DoRed | DoGreen | DoBlue;
  65.   if (!XAllocColor (XtDisplay (w), cmap, &xcolor))
  66.     {
  67.       printf ("Couldn't allocate color!\n");
  68.       exit (1);
  69.     }
  70.   return xcolor.pixel;
  71. }
  72.  
  73. /* This is rather inefficient, but we don't mind for the moment,
  74.    because it works.  */
  75.  
  76. static void
  77. translate_pixels (Widget to, Widget from, ...)
  78. {
  79.   va_list ap;
  80.   char *name;
  81.   Colormap from_cmap, to_cmap;
  82.   XColor xcolor;
  83.  
  84.   XtVaGetValues (from, XtNcolormap, &from_cmap, NULL);
  85.   XtVaGetValues (to, XtNcolormap, &to_cmap, NULL);
  86.  
  87.   va_start (ap, from);
  88.   for (name = va_arg (ap, char *); name != NULL; name = va_arg (ap, char *))
  89.     {
  90.       XtVaGetValues (from, name, &xcolor.pixel, NULL);
  91.       XQueryColor (XtDisplay (from), from_cmap, &xcolor);
  92.       if (!XAllocColor (XtDisplay (to), to_cmap, &xcolor))
  93.     XtAppWarning (XtWidgetToApplicationContext (to),
  94.               "Couldn't allocate color!\n");
  95.       else
  96.     XtVaSetValues (from, name, xcolor.pixel, NULL);
  97.     }
  98.   va_end (ap);
  99. }
  100.  
  101. static Widget
  102. create_command (Widget parent, char *name, XtCallbackProc cb)
  103. {
  104.   Widget ok;
  105.   ok = XtVaCreateManagedWidget (name, commandWidgetClass, parent, NULL);
  106.   XtAddCallback (ok, XtNcallback, cb, NULL);
  107.   return ok;
  108. }
  109.  
  110. GLuint light, material;
  111. Widget mesa;
  112.  
  113. void
  114. setup_light (void)
  115. {
  116.   GLfloat light_ambient[] = {0.0, 0.0, 0.0, 1.0};
  117.   GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
  118.   GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
  119.  
  120.   /* light_position is NOT default value */
  121.   GLfloat light_position[] = {1.0, 0.0, 0.0, 0.0};
  122.   GLfloat global_ambient[] = {0.75, 0.75, 0.75, 1.0};
  123.  
  124.   glLightfv (GL_LIGHT0, GL_AMBIENT, light_ambient);
  125.   glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  126.   glLightfv (GL_LIGHT0, GL_SPECULAR, light_specular);
  127.   glLightfv (GL_LIGHT0, GL_POSITION, light_position);
  128.  
  129.   glLightModelfv (GL_LIGHT_MODEL_AMBIENT, global_ambient);
  130. }
  131.  
  132. static XtTranslations toggle_translations;
  133. static char toggle_translation_string[] =
  134.   "<Btn1Down>,<Btn1Up>: set() notify()";
  135.  
  136. enum light_source { FIX_OBJ, FIX_OBS };
  137.   
  138. static void
  139. light_cb (Widget w, XtPointer client_data, XtPointer junk)
  140. {
  141.   switch ((enum light_source) client_data)
  142.     {
  143.     case FIX_OBJ:
  144.       /* Fixed wrt object: perform the light setup in the the LIGHT list.  */
  145.       glNewList (light, GL_COMPILE);
  146.         setup_light ();
  147.       glEndList ();
  148.       break;
  149.     case FIX_OBS:
  150.       /* Fixed wrt observer: nuke the LIGHT list and setup the
  151.      light in the default coordinate system.  */
  152.       glNewList (light, GL_COMPILE);
  153.       glEndList ();
  154.       glPushMatrix ();
  155.         glLoadIdentity ();
  156.     setup_light ();
  157.       glPopMatrix ();
  158.       break;
  159.     }
  160.   GLwRedrawObjects (mesa);
  161. }
  162.  
  163. enum material_mode { MAT_GOLD, MAT_RUBY, MAT_EMERALD };
  164.   
  165. static void
  166. material_cb (Widget w, XtPointer client_data, XtPointer junk)
  167. {
  168.   GLfloat gold_ambient[] = {0.24725, 0.1995, 0.0745, 1.0};
  169.   GLfloat gold_diffuse[] = {0.75164, 0.60648, 0.22648, 1.0};
  170.   GLfloat gold_specular[] = {0.628281, 0.555802, 0.366065, 1.0};
  171.   GLfloat gold_shine = 0.4;
  172.   
  173.   GLfloat ruby_ambient[] = {0.1745, 0.01175, 0.01175, 1.0};
  174.   GLfloat ruby_diffuse[] = {0.61424, 0.04136, 0.04136, 1.0};
  175.   GLfloat ruby_specular[] = {0.727811, 0.626959, 0.626959, 1.0};
  176.   GLfloat ruby_shine = 0.6;
  177.   
  178.   GLfloat emerald_ambient[] = {0.0215, 0.1745, 0.0215, 1.0};
  179.   GLfloat emerald_diffuse[] = {0.07568, 0.61424, 0.07568, 1.0};
  180.   GLfloat emerald_specular[] = {0.633, 0.727811, 0.633, 1.0};
  181.   GLfloat emerald_shine = 0.6;
  182.   
  183.   glNewList (material, GL_COMPILE);
  184.   {
  185.     switch ((enum material_mode) client_data)
  186.       {
  187.       case MAT_GOLD:
  188.     glMaterialfv (GL_FRONT, GL_AMBIENT, gold_ambient);
  189.     glMaterialfv (GL_FRONT, GL_DIFFUSE, gold_diffuse);
  190.     glMaterialfv (GL_FRONT, GL_SPECULAR, gold_specular);
  191.     glMaterialf (GL_FRONT, GL_SHININESS, gold_shine*128.0);
  192.     break;
  193.       case MAT_RUBY:
  194.     glMaterialfv (GL_FRONT, GL_AMBIENT, ruby_ambient);
  195.     glMaterialfv (GL_FRONT, GL_DIFFUSE, ruby_diffuse);
  196.     glMaterialfv (GL_FRONT, GL_SPECULAR, ruby_specular);
  197.     glMaterialf (GL_FRONT, GL_SHININESS, ruby_shine*128.0);
  198.     break;
  199.       case MAT_EMERALD:
  200.     glMaterialfv (GL_FRONT, GL_AMBIENT, emerald_ambient);
  201.     glMaterialfv (GL_FRONT, GL_DIFFUSE, emerald_diffuse);
  202.     glMaterialfv (GL_FRONT, GL_SPECULAR, emerald_specular);
  203.     glMaterialf (GL_FRONT, GL_SHININESS, emerald_shine*128.0);
  204.     break;
  205.       }
  206.   }
  207.   glEndList ();
  208.   GLwRedrawObjects (mesa);
  209. }
  210.  
  211. void
  212. quit_function (Widget w, XtPointer closure, XtPointer call_data)
  213. {
  214.   exit (0);
  215. }
  216.  
  217. static String fallback_resources[] =
  218. {
  219.   "*MesaWorkstation.debug: false",
  220.   "*MesaWorkstation.installColormap: true",
  221.   "*MesaWorkstation.ximage: true",
  222.   "*MesaWorkstation.doublebuffer: false",
  223.   "*quit.label: Exit",
  224.   "*mesa.width: 400",
  225.   "*mesa.height: 400",
  226.   NULL
  227. };
  228.  
  229. int
  230. main (int argc, char *argv[])
  231. {
  232.   Widget top, frame, quit;
  233.   Widget fix_obj, fix_obs;
  234.   Widget gold, ruby, emerald;
  235.   XtAppContext app_context;
  236.   Boolean cmap_installed;
  237.   GLuint teapot;
  238.  
  239.   XtSetLanguageProc (NULL, NULL, NULL);
  240.   top = XtVaAppInitialize (&app_context, "Tea", NULL, 0,
  241.                &argc, argv, fallback_resources, NULL);
  242.  
  243.   frame = XtVaCreateManagedWidget ("frame", formWidgetClass,
  244.                    top,
  245.                    NULL);
  246.   mesa = XtVaCreateManagedWidget ("mesa", mesaWorkstationWidgetClass,
  247.                   frame,
  248.                   GLwNrgba, True,
  249.                   NULL);
  250.  
  251.   fix_obj = XtVaCreateManagedWidget ("fix_obj", toggleWidgetClass,
  252.                      frame,
  253.                      XtNlabel, "light fixed wrt object",
  254.                      XtNstate, False,
  255.                      XtNfromHoriz, mesa, XtNhorizDistance, 10,
  256.                      NULL);
  257.   fix_obs = XtVaCreateManagedWidget ("fix_obs", toggleWidgetClass,
  258.                      frame,
  259.                      XtNlabel, "light fixed wrt observer",
  260.                      XtNstate, True,
  261.                      XtNradioGroup, fix_obj,
  262.                      XtNfromVert, fix_obj, XtNvertDistance, 0,
  263.                      XtNfromHoriz, mesa, XtNhorizDistance, 10,
  264.                      NULL);
  265.   toggle_translations = XtParseTranslationTable (toggle_translation_string);
  266.   XtOverrideTranslations (fix_obj, toggle_translations);
  267.   XtOverrideTranslations (fix_obs, toggle_translations);
  268.   XtAddCallback (fix_obj, XtNcallback, light_cb, (XtPointer) FIX_OBJ);
  269.   XtAddCallback (fix_obs, XtNcallback, light_cb, (XtPointer) FIX_OBS);
  270.  
  271.   gold = XtVaCreateManagedWidget ("gold", toggleWidgetClass,
  272.                   frame,
  273.                   XtNlabel, "gold",
  274.                   XtNstate, True,
  275.                   XtNfromVert, fix_obs, XtNvertDistance, 20,
  276.                   XtNfromHoriz, mesa, XtNhorizDistance, 10,
  277.                   NULL);
  278.   ruby = XtVaCreateManagedWidget ("ruby", toggleWidgetClass,
  279.                   frame,
  280.                   XtNlabel, "ruby",
  281.                   XtNstate, False,
  282.                   XtNradioGroup, gold,
  283.                   XtNfromVert, gold, XtNvertDistance, 0,
  284.                   XtNfromHoriz, mesa, XtNhorizDistance, 10,
  285.                   NULL);
  286.   emerald = XtVaCreateManagedWidget ("emerald", toggleWidgetClass,
  287.                      frame,
  288.                      XtNlabel, "emerald",
  289.                      XtNstate, False,
  290.                      XtNradioGroup, gold,
  291.                      XtNfromVert, ruby, XtNvertDistance, 0,
  292.                      XtNfromHoriz, mesa, XtNhorizDistance, 10,
  293.                      NULL);
  294.   XtOverrideTranslations (gold, toggle_translations);
  295.   XtOverrideTranslations (ruby, toggle_translations);
  296.   XtOverrideTranslations (emerald, toggle_translations);
  297.   XtAddCallback (gold, XtNcallback, material_cb, (XtPointer) MAT_GOLD);
  298.   XtAddCallback (ruby, XtNcallback, material_cb, (XtPointer) MAT_RUBY);
  299.   XtAddCallback (emerald, XtNcallback, material_cb, (XtPointer) MAT_EMERALD);
  300.  
  301.   quit = XtVaCreateManagedWidget ("quit", commandWidgetClass,
  302.                   frame,
  303.                   XtNfromVert, emerald, XtNvertDistance, 50,
  304.                   XtNfromHoriz, mesa, XtNhorizDistance, 10,
  305.                   NULL);
  306.   XtAddCallback (quit, XtNcallback, quit_function, NULL);
  307.  
  308.   XtRealizeWidget (top);
  309.  
  310.   XtVaGetValues (mesa, GLwNinstallColormap, &cmap_installed, NULL);
  311.   if (cmap_installed)
  312.     {
  313.       translate_pixels (mesa, quit,
  314.             XtNbackground, XtNforeground, XtNborder, NULL);
  315.       translate_pixels (mesa, fix_obj,
  316.             XtNbackground, XtNforeground, XtNborder, NULL);
  317.       translate_pixels (mesa, fix_obs,
  318.             XtNbackground, XtNforeground, XtNborder, NULL);
  319.       translate_pixels (mesa, gold,
  320.             XtNbackground, XtNforeground, XtNborder, NULL);
  321.       translate_pixels (mesa, ruby,
  322.             XtNbackground, XtNforeground, XtNborder, NULL);
  323.       translate_pixels (mesa, emerald,
  324.             XtNbackground, XtNforeground, XtNborder, NULL);
  325.       translate_pixels (mesa, frame, XtNbackground, XtNborder, NULL);
  326.       XWarpPointer (XtDisplay (mesa), None, XtWindow (mesa),
  327.             0, 0, 0, 0, 0, 0);
  328.     }
  329.  
  330.   GLwMakeCurrent (mesa);
  331.  
  332.   glFrontFace (GL_CW);
  333.   glEnable (GL_LIGHTING);
  334.   glEnable (GL_LIGHT0);
  335.   glEnable (GL_AUTO_NORMAL);
  336.   glEnable (GL_NORMALIZE);
  337.   glEnable (GL_DEPTH_TEST);
  338.   glDepthFunc (GL_LESS);
  339.  
  340.   GLwSetFrustumProjection (mesa, -1.0, 1.0, -1.0, 1.0, 1.0, 10.0);
  341.   GLwSetPolarView (mesa, 3.0, 2*M_PI/3, -M_PI/3);
  342.  
  343.   teapot = glGenLists (1);
  344.   glNewList (teapot, GL_COMPILE);
  345.   {
  346.     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  347.     glutSolidTeapot (1.0);
  348.   }
  349.   glEndList ();
  350.  
  351.   light = glGenLists (1);
  352.   glNewList (light, GL_COMPILE);
  353.   glEndList ();
  354.  
  355.   material = glGenLists (1);
  356.   glNewList (material, GL_COMPILE);
  357.   glEndList ();
  358.  
  359.   material_cb (NULL, (XtPointer) MAT_GOLD, NULL);
  360.   light_cb (NULL, (XtPointer) FIX_OBS, NULL);
  361.  
  362.   GLwPostObject (mesa, light);
  363.   GLwPostObject (mesa, material);
  364.   GLwPostObject (mesa, teapot);
  365.  
  366.   XtAppMainLoop (app_context);
  367.   return (0);
  368. }
  369.  
  370.  
  371. /* Copyright (c) Mark J. Kilgard, 1994. */
  372.  
  373. /**
  374. (c) Copyright 1993, Silicon Graphics, Inc.
  375.  
  376. ALL RIGHTS RESERVED
  377.  
  378. Permission to use, copy, modify, and distribute this software
  379. for any purpose and without fee is hereby granted, provided
  380. that the above copyright notice appear in all copies and that
  381. both the copyright notice and this permission notice appear in
  382. supporting documentation, and that the name of Silicon
  383. Graphics, Inc. not be used in advertising or publicity
  384. pertaining to distribution of the software without specific,
  385. written prior permission.
  386.  
  387. THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU
  388. "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR
  389. OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  390. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  IN NO
  391. EVENT SHALL SILICON GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE
  392. ELSE FOR ANY DIRECT, SPECIAL, INCIDENTAL, INDIRECT OR
  393. CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER,
  394. INCLUDING WITHOUT LIMITATION, LOSS OF PROFIT, LOSS OF USE,
  395. SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD PARTIES, WHETHER OR
  396. NOT SILICON GRAPHICS, INC.  HAS BEEN ADVISED OF THE POSSIBILITY
  397. OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  398. ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE OR
  399. PERFORMANCE OF THIS SOFTWARE.
  400.  
  401. US Government Users Restricted Rights
  402.  
  403. Use, duplication, or disclosure by the Government is subject to
  404. restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  405. (c)(1)(ii) of the Rights in Technical Data and Computer
  406. Software clause at DFARS 252.227-7013 and/or in similar or
  407. successor clauses in the FAR or the DOD or NASA FAR
  408. Supplement.  Unpublished-- rights reserved under the copyright
  409. laws of the United States.  Contractor/manufacturer is Silicon
  410. Graphics, Inc., 2011 N.  Shoreline Blvd., Mountain View, CA
  411. 94039-7311.
  412.  
  413. OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  414. */
  415.  
  416. #include <GL/gl.h>
  417. /* #include <GL/glut.h> */
  418.  
  419. /* Rim, body, lid, and bottom data must be reflected in x
  420.    and y; handle and spout data across the y axis only.  */
  421.  
  422. long patchdata[][16] =
  423. {
  424.     /* rim */
  425.   {102, 103, 104, 105, 4, 5, 6, 7, 8, 9, 10, 11,
  426.     12, 13, 14, 15},
  427.     /* body */
  428.   {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
  429.     24, 25, 26, 27},
  430.   {24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36,
  431.     37, 38, 39, 40},
  432.     /* lid */
  433.   {96, 96, 96, 96, 97, 98, 99, 100, 101, 101, 101,
  434.     101, 0, 1, 2, 3,},
  435.   {0, 1, 2, 3, 106, 107, 108, 109, 110, 111, 112,
  436.     113, 114, 115, 116, 117},
  437.     /* bottom */
  438.   {118, 118, 118, 118, 124, 122, 119, 121, 123, 126,
  439.     125, 120, 40, 39, 38, 37},
  440.     /* handle */
  441.   {41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
  442.     53, 54, 55, 56},
  443.   {53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
  444.     28, 65, 66, 67},
  445.     /* spout */
  446.   {68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  447.     80, 81, 82, 83},
  448.   {80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
  449.     92, 93, 94, 95}
  450. };
  451. /* *INDENT-OFF* */
  452.  
  453. float cpdata[][3] =
  454. {
  455.     {0.2, 0, 2.7}, {0.2, -0.112, 2.7}, {0.112, -0.2, 2.7}, {0,
  456.     -0.2, 2.7}, {1.3375, 0, 2.53125}, {1.3375, -0.749, 2.53125},
  457.     {0.749, -1.3375, 2.53125}, {0, -1.3375, 2.53125}, {1.4375,
  458.     0, 2.53125}, {1.4375, -0.805, 2.53125}, {0.805, -1.4375,
  459.     2.53125}, {0, -1.4375, 2.53125}, {1.5, 0, 2.4}, {1.5, -0.84,
  460.     2.4}, {0.84, -1.5, 2.4}, {0, -1.5, 2.4}, {1.75, 0, 1.875},
  461.     {1.75, -0.98, 1.875}, {0.98, -1.75, 1.875}, {0, -1.75,
  462.     1.875}, {2, 0, 1.35}, {2, -1.12, 1.35}, {1.12, -2, 1.35},
  463.     {0, -2, 1.35}, {2, 0, 0.9}, {2, -1.12, 0.9}, {1.12, -2,
  464.     0.9}, {0, -2, 0.9}, {-2, 0, 0.9}, {2, 0, 0.45}, {2, -1.12,
  465.     0.45}, {1.12, -2, 0.45}, {0, -2, 0.45}, {1.5, 0, 0.225},
  466.     {1.5, -0.84, 0.225}, {0.84, -1.5, 0.225}, {0, -1.5, 0.225},
  467.     {1.5, 0, 0.15}, {1.5, -0.84, 0.15}, {0.84, -1.5, 0.15}, {0,
  468.     -1.5, 0.15}, {-1.6, 0, 2.025}, {-1.6, -0.3, 2.025}, {-1.5,
  469.     -0.3, 2.25}, {-1.5, 0, 2.25}, {-2.3, 0, 2.025}, {-2.3, -0.3,
  470.     2.025}, {-2.5, -0.3, 2.25}, {-2.5, 0, 2.25}, {-2.7, 0,
  471.     2.025}, {-2.7, -0.3, 2.025}, {-3, -0.3, 2.25}, {-3, 0,
  472.     2.25}, {-2.7, 0, 1.8}, {-2.7, -0.3, 1.8}, {-3, -0.3, 1.8},
  473.     {-3, 0, 1.8}, {-2.7, 0, 1.575}, {-2.7, -0.3, 1.575}, {-3,
  474.     -0.3, 1.35}, {-3, 0, 1.35}, {-2.5, 0, 1.125}, {-2.5, -0.3,
  475.     1.125}, {-2.65, -0.3, 0.9375}, {-2.65, 0, 0.9375}, {-2,
  476.     -0.3, 0.9}, {-1.9, -0.3, 0.6}, {-1.9, 0, 0.6}, {1.7, 0,
  477.     1.425}, {1.7, -0.66, 1.425}, {1.7, -0.66, 0.6}, {1.7, 0,
  478.     0.6}, {2.6, 0, 1.425}, {2.6, -0.66, 1.425}, {3.1, -0.66,
  479.     0.825}, {3.1, 0, 0.825}, {2.3, 0, 2.1}, {2.3, -0.25, 2.1},
  480.     {2.4, -0.25, 2.025}, {2.4, 0, 2.025}, {2.7, 0, 2.4}, {2.7,
  481.     -0.25, 2.4}, {3.3, -0.25, 2.4}, {3.3, 0, 2.4}, {2.8, 0,
  482.     2.475}, {2.8, -0.25, 2.475}, {3.525, -0.25, 2.49375},
  483.     {3.525, 0, 2.49375}, {2.9, 0, 2.475}, {2.9, -0.15, 2.475},
  484.     {3.45, -0.15, 2.5125}, {3.45, 0, 2.5125}, {2.8, 0, 2.4},
  485.     {2.8, -0.15, 2.4}, {3.2, -0.15, 2.4}, {3.2, 0, 2.4}, {0, 0,
  486.     3.15}, {0.8, 0, 3.15}, {0.8, -0.45, 3.15}, {0.45, -0.8,
  487.     3.15}, {0, -0.8, 3.15}, {0, 0, 2.85}, {1.4, 0, 2.4}, {1.4,
  488.     -0.784, 2.4}, {0.784, -1.4, 2.4}, {0, -1.4, 2.4}, {0.4, 0,
  489.     2.55}, {0.4, -0.224, 2.55}, {0.224, -0.4, 2.55}, {0, -0.4,
  490.     2.55}, {1.3, 0, 2.55}, {1.3, -0.728, 2.55}, {0.728, -1.3,
  491.     2.55}, {0, -1.3, 2.55}, {1.3, 0, 2.4}, {1.3, -0.728, 2.4},
  492.     {0.728, -1.3, 2.4}, {0, -1.3, 2.4}, {0, 0, 0}, {1.425,
  493.     -0.798, 0}, {1.5, 0, 0.075}, {1.425, 0, 0}, {0.798, -1.425,
  494.     0}, {0, -1.5, 0.075}, {0, -1.425, 0}, {1.5, -0.84, 0.075},
  495.     {0.84, -1.5, 0.075}
  496. };
  497.  
  498. static float tex[2][2][2] =
  499. {
  500.   { {0, 0},
  501.     {1, 0}},
  502.   { {0, 1},
  503.     {1, 1}}
  504. };
  505.  
  506. /* *INDENT-ON* */
  507.  
  508. static void
  509. teapot(GLint grid, GLdouble scale, GLenum type)
  510. {
  511.   float p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3];
  512.   long i, j, k, l;
  513.  
  514.   glPushAttrib(GL_ENABLE_BIT | GL_EVAL_BIT);
  515.   glEnable(GL_AUTO_NORMAL);
  516.   glEnable(GL_NORMALIZE);
  517.   glEnable(GL_MAP2_VERTEX_3);
  518.   glEnable(GL_MAP2_TEXTURE_COORD_2);
  519.   glPushMatrix();
  520.   /* glRotatef(270.0, 1.0, 0.0, 0.0); */
  521.   /* Rotate it upwards in the standard MesaWorkstation
  522.      coordinate system.  */
  523.   glRotatef(90.0, 0.0, 1.0, 0.0);
  524.   glRotatef(90.0, 1.0, 0.0, 0.0);
  525.   glScalef(0.5 * scale, 0.5 * scale, 0.5 * scale);
  526.   glTranslatef(0.0, 0.0, -1.5);
  527.   for (i = 0; i < 10; i++) {
  528.     for (j = 0; j < 4; j++) {
  529.       for (k = 0; k < 4; k++) {
  530.         for (l = 0; l < 3; l++) {
  531.           p[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l];
  532.           q[j][k][l] = cpdata[patchdata[i][j * 4 + (3 - k)]][l];
  533.           if (l == 1)
  534.             q[j][k][l] *= -1.0;
  535.           if (i < 6) {
  536.             r[j][k][l] =
  537.               cpdata[patchdata[i][j * 4 + (3 - k)]][l];
  538.             if (l == 0)
  539.               r[j][k][l] *= -1.0;
  540.             s[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l];
  541.             if (l == 0)
  542.               s[j][k][l] *= -1.0;
  543.             if (l == 1)
  544.               s[j][k][l] *= -1.0;
  545.           }
  546.         }
  547.       }
  548.     }
  549.     glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2,
  550.       &tex[0][0][0]);
  551.     glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4,
  552.       &p[0][0][0]);
  553.     glMapGrid2f(grid, 0.0, 1.0, grid, 0.0, 1.0);
  554.     glEvalMesh2(type, 0, grid, 0, grid);
  555.     glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4,
  556.       &q[0][0][0]);
  557.     glEvalMesh2(type, 0, grid, 0, grid);
  558.     if (i < 6) {
  559.       glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4,
  560.         &r[0][0][0]);
  561.       glEvalMesh2(type, 0, grid, 0, grid);
  562.       glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4,
  563.         &s[0][0][0]);
  564.       glEvalMesh2(type, 0, grid, 0, grid);
  565.     }
  566.   }
  567.   glPopMatrix();
  568.   glPopAttrib();
  569. }
  570.  
  571. /* CENTRY */
  572. void
  573. glutSolidTeapot(GLdouble scale)
  574. {
  575.   teapot(14, scale, GL_FILL);
  576. }
  577.  
  578. void
  579. glutWireTeapot(GLdouble scale)
  580. {
  581.   teapot(10, scale, GL_LINE);
  582. }
  583. /* ENDCENTRY */
  584.